package com.AJava1710D.xiancheng;

import org.apache.ibatis.annotations.Insert;

import java.util.List;

/**
 * 作者: LCG
 * 日期: 2020/6/23 09:05
 * 描述: synchronized 加在普通方法和静态方法的区别
 */
public class RunableB implements Runnable {

    private List<Integer> list;

    public RunableB(List<Integer> list) {
        this.list = list;
    }

    @Override
    public void run() {

        for (int i=0;i<5000;i++){
            try {
                System.out.println("======add  B ========");
                this.add01(i);
                Thread.sleep(0);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }

    }

    /**
     * synchronized在普通方法上
     * @param integer
     */
    public synchronized void  add01(Integer integer){

        list.add(integer);

    }


    /**
     * synchronized在普通方法上
     * @param integer
     */
    public static synchronized void  add02(Integer integer){

       // list.add(integer);

    }


}
